Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php // Admin part of the plugin // Defines the plugin name, version, and two example..
Decoded Output download
<?php
// Admin part of the plugin
// Defines the plugin name, version, and two examples hooks for how to enqueue the admin-specific stylesheet and JavaScript
class class_MRWP_admin {
// Privaye var
private $plugin_name; // name of the plugin
private $version; // current version of the plugin
private $current_version; // current version of the plugin
private $menu_position; // menu position of the plugin
// Initialize the class and set its properties.
public function __construct($plugin_name, $version, $current_version, $menu_position) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->current_version = $current_version;
$this->menu_position = $menu_position;
}
// Register the stylesheets for the admin area
public function enqueue_styles() {
wp_enqueue_style( 'woocommerce_admin', plugins_url().'/' . class_MRWP_main::WOOCOMMERCE_FOLDER . '/assets/css/admin.css', $this->version, 'all' );
wp_enqueue_style( 'mondialrelay_admin', plugin_dir_url(dirname(__FILE__)).'admin/css/MRWP-admin.css', $this->version, 'all' );
}
// Register the JavaScript for the admin area
public function enqueue_scripts( $hook_suffix ) {
// WooCommerce scripts
$this->woocommerce_scripts();
// Mondial Relay scripts
wp_register_script( 'jquery_validate', plugin_dir_url(dirname(__FILE__)).'admin/js/jquery.validate.min.js', array( 'jquery'));
wp_enqueue_script( 'jquery_validate', $this->version, false);
wp_register_script( 'mondialrelay_admin_validate', plugin_dir_url(dirname(__FILE__)).'admin/js/MRWP-admin.js', array( 'jquery'));
// Localize the script with new data
$translation_array = array(
'message1' => __(' < Entrez votre code client', 'mondialrelay-wordpress'),
'message2' => __(' < Votre code client doit tre de 8 caractres', 'mondialrelay-wordpress'),
'message3' => __(' < Entrez votre code marque', 'mondialrelay-wordpress'),
'message4' => __(' < Entrez votre cl priv', 'mondialrelay-wordpress'),
'message5' => __(' < Entrez votre niveau d\'assurance', 'mondialrelay-wordpress'),
'message6' => __(' < Entrez un nombre valide', 'mondialrelay-wordpress'),
'message7' => __(' < Entrez votre nom d\'expditeur', 'mondialrelay-wordpress'),
'message8' => __(' < Votre nom d\'expditeur doit contenir au maximum 32 caractres', 'mondialrelay-wordpress'),
'message9' => __(' < Votre complment d\'expditeur doit contenir au maximum 32 caractres', 'mondialrelay-wordpress'),
'message10' => __(' < Entrez votre rue', 'mondialrelay-wordpress'),
'message11' => __(' < Votre rue doit contenir au maximum 32 caractres', 'mondialrelay-wordpress'),
'message12' => __(' < Entrez votre code postal', 'mondialrelay-wordpress'),
'message13' => __(' < Votre code postal doit contenir au maximum 5 caractres', 'mondialrelay-wordpress'),
'message14' => __(' < Entrez votre ville', 'mondialrelay-wordpress'),
'message15' => __(' < Votre ville doit contenir au maximum 26 caractres', 'mondialrelay-wordpress'),
'message16' => __(' < Entrez votre pays', 'mondialrelay-wordpress'),
'message17' => __(' < Votre pays doit contenir au maximum 2 caractres', 'mondialrelay-wordpress'),
'message18' => __(' < Entrez votre numro de tlphone', 'mondialrelay-wordpress'),
'message19' => __(' < Votre numro de tlphone doit contenir au maximum 13 caractres', 'mondialrelay-wordpress'),
'message20' => __(' < Votre adresse e-mail doit contenir au maximum 70 caractres', 'mondialrelay-wordpress'),
'message21' => __(' ^ Entrez un sujet', 'mondialrelay-wordpress'),
'message22' => __(' ^ Entrez le contenu de votre email', 'mondialrelay-wordpress'),
'message23' => __(' < Choisissez la position du menu du plugin Mondial Relay', 'mondialrelay-wordpress'),
'message24' => __(' < Votre complment d\'adresse doit contenir au maximum 32 caractres', 'mondialrelay-wordpress'),
);
wp_localize_script( 'mondialrelay_admin_validate', 'MRWP_i18n', $translation_array );
// @todo Refactoring Revoir tous les wp_register_script() et wp_enqueue_script() qui ne sont pas corrects
wp_enqueue_script( 'mondialrelay_admin_validate', $this->version, false);
// Only enqueue the zones export script in the appropriate page
if ( 'toplevel_page_wp-mondialrelay' == $hook_suffix ) {
wp_register_script( 'mondialrelay_zones', plugin_dir_url( __DIR__ ) . 'admin/js/shipping-zones.js', array( 'jquery' ), $this->version );
wp_enqueue_script( 'mondialrelay_zones' ) ;
}
}
/**
* Enqueue JS for Ajax WP_List_Table
*/
public function enqueue_list_script() {
wp_register_script( 'mondialrelay_admin_mass_shipping', plugin_dir_url(dirname(__FILE__)). 'admin/js/list-table.js', array( 'jquery', 'jquery-ui-datepicker' ) );
wp_enqueue_script( 'mondialrelay_admin_mass_shipping', $this->version, false);
// Date picker
wp_enqueue_script( 'jquery-ui-datepicker' );
/* Choose jQuery UI theme on this page
* https://jqueryui.com/themeroller/#!zThemeParams=5d00008000ea05000000000000003d8888d844329a8dfe02723de3e5701258a13d5ba490adca99e4a02bf259c3083bccd292fbc7a815b30f470ff7864f8c0d0abbfd0926063d14faae19f29b086c2f4cf156a8205f7f8a4665545a5673e9f68749a54ab4746c69d599dce963fc3aa65b2c0af8483da4f905056d9752840f949d1956aecdd062dd566cab69194f70740c7a8eb43b906c3dfb317e62615319e0ccabb3fa3370a66b6d22a53a0ae6b209b465064ce1462b9be2cf60c233a80f57f75a7c2f469e6b8439ad8c1db376bb6a8cdfd2627f4334b44198e955e4256b0a8a6ee6d2f45da7567e0f7aa22c9d81d684db86e18ece2497400fe0f135cc38bfd1e55939aeda6c2ecfdab826c6779b110967ae1299dff254dcd78dd5b26dd2df26cffa81bbc523debff64e26be65e6a620c045190e203904e9d81bcea2f4834a2016ed531ec391294e7673cab97b38ffe66c2dc20e96b09790d2ca260d9b778eb49c95cf80aece999855d79bbd8568647998fac2fcbce76524897433dc876aa689b6bc8494075f7ec0a68f66d3f2417247e5b022db641f3a79f968edd1bf078f7f6b79d5faf38bb47379b04163fb66f4b32fa24b8722298ca1f9505a194f03142c8f3dc1affe3191d6
*
* Theme name goes after 1.12.1/themes/
* Eg 1.12.1/themes/flick/
*/
wp_enqueue_style( 'mrwp-jquery-ui','https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/flick/jquery-ui.css', false, '1.12.1', false );
}
// Register the WooCommerce JavaScript for the admin area
public function woocommerce_scripts() {
// Register scripts
wp_register_script( 'woocommerce_admin', plugins_url().'/' . class_MRWP_main::WOOCOMMERCE_FOLDER . '/assets/js/admin/woocommerce_admin.min.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION );
wp_register_script( 'jquery-blockui', plugins_url().'/' . class_MRWP_main::WOOCOMMERCE_FOLDER . '/assets/js/jquery-blockui/jquery.blockUI.min.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'jquery-tiptip', plugins_url().'/' . class_MRWP_main::WOOCOMMERCE_FOLDER . '/assets/js/jquery-tiptip/jquery.tipTip.min.js', array( 'jquery' ), WC_VERSION,true );
// Enqueue scripts
//wp_enqueue_script( 'iris' );
//wp_enqueue_script( 'woocommerce_admin' );
}
// Show row meta on the plugin screen
public static function plugin_row_meta( $links, $file ) {
if ( strpos( $file, class_MRWP_main::PLUGIN_NAME ) !== false ) {
$new_links = array(
'<a href="' . class_MRWP_main::DOCUMENTATION . '" target="_blank">' . __('Documentation', 'mondialrelay-wordpress') . '</a>',
'<a href="' . class_MRWP_main::CLIENT . '" target="_blank">' . __('Espace client', 'mondialrelay-wordpress') . '</a>',
);
$links = array_merge( $links, $new_links );
}
return $links;
}
// Add Mondial Relay menu
public function MondialRelayMenu() {
$mondialrelay_menu_position = get_option( 'mondialrelay_menu_position', class_MRWP_main::MENU_POSITION );
add_menu_page(
__('Mondial Relay - Mondial Relay pour WordPress', 'mondialrelay-wordpress'),
__('Mondial Relay', 'mondialrelay-wordpress'),
'manage_woocommerce',
'wp-mondialrelay',
array($this, 'MondialRelayPage'),
'dashicons-location',
$mondialrelay_menu_position
);
$pagename = add_submenu_page(
'wp-mondialrelay',
__('Cration en masse - Mondial Relay pour WordPress', 'mondialrelay-wordpress'),
__('Cration en masse', 'mondialrelay-wordpress'),
'manage_woocommerce',
'wp-mondialrelay-mass-expeditions',
array( $this, 'MondialRelayMassShipping' )
);
// Enqueue JS for this page only
// @see https://wordpress.stackexchange.com/a/76420
add_action( 'load-' . $pagename, array( $this, 'enqueue_list_script' ) );
$pagename = add_submenu_page(
'wp-mondialrelay',
__('Expditions - Mondial Relay pour WordPress', 'mondialrelay-wordpress'),
__('Expditions', 'mondialrelay-wordpress'),
'manage_woocommerce',
'wp-mondialrelay-expeditions',
array( $this, 'MondialRelayShipping' )
);
// Enqueue JS for this page only
add_action( 'load-' . $pagename, array( $this, 'enqueue_list_script' ) );
add_submenu_page(
'wp-mondialrelay',
__('Maintenance - Mondial Relay pour WordPress', 'mondialrelay-wordpress'),
__('Maintenance', 'mondialrelay-wordpress'),
'manage_woocommerce',
'wp-mondialrelay-maintenance',
array($this, 'MondialRelayMaintenance')
);
}
// Notification when the plugin has an update available
public function notificationMenu() {
if (false !== ($contents = @file_get_contents($this->current_version))) {
$current = file_get_contents($this->current_version);
} else {
$current = $this->version;
}
if (version_compare($this->version, $current, '<')) {
$submenu['wp-mondialrelay'][5][0] .= "<span class='update-plugins count-1'><span class='update-count'>1</span></span>";
$menu[$this->menu_position][0] .= "<span class='update-plugins count-1'><span class='update-count'>1</span></span>";
}
}
// Mondial Relay options page
function MondialRelayPage($settings) {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/parts/MRWP-admin-page.php';
}
// Expeditions listing page of Mondial Relay
function MondialRelayShipping($settings) {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/parts/MRWP-admin-history.php';
}
// Mass Expeditions
function MondialRelayMassShipping($settings) {
require_once plugin_dir_path( __DIR__ ) . 'admin/parts/MRWP-admin-mass-shipping.php';
}
// Mondial Relay maintenance page
function MondialRelayMaintenance($settings) {
global $wpdb;
$prefixe = $wpdb->prefix;
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/parts/MRWP-admin-maintenance.php';
}
// Mondial Relay in a WooCommerce order
function actions_mr_meta_box($order_id) {
add_meta_box(
'mondialrelay_expedition_meta_box',
__( 'Mondial Relay', 'mondialrelay-wordpress' ),
array($this, 'actions_mr_meta_box_callback'),
'shop_order',
'side'
);
}
// Mondial Relay function in a WooCommerce order
function actions_mr_meta_box_callback( $order ) {
global $wpdb;
$prefixe = $wpdb->prefix;
$order_id = $order->ID;
// Check if the order uses Mondial Relay
$mondial_relay_shipping_code = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Shipping Code');
$isMR = $mondial_relay_shipping_code;
if (isset($isMR) && $isMR != 'HMR' && $isMR != '' ) {
// Display the right box
wp_nonce_field( 'actions_mr_meta_box', 'actions_mr_meta_box_nonce' );
// Check if a Mondial Relay expedition already exists
$exist_expedition = class_MRWP_db::get_meta_champ($order_id, 'ExpeditionNum', 1);
// A Mondial Relay expedition already exists for this order
if (isset($exist_expedition) && $exist_expedition) {
$expedition_num = class_MRWP_db::get_meta_champ($order_id, 'ExpeditionNum');
$expedition_statusid = class_MRWP_db::get_meta_champ($order_id, 'ExpeditionStatus');
$expedition_status = class_MRWP_helpers::etat_expedition($expedition_statusid);
// Get Mondial Relais oint if exists
$point_mondial_relay = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Parcel Shop ID');
?>
<table class="wp-list-table widefat fixed striped">
<tbody>
<tr>
<td width="60%" style="text-align: left"><?php _e('Expdition', 'mondialrelay-wordpress') ?></td>
<td width="40%" style="text-align: right"><strong><?php echo $expedition_num ?></strong></td>
</tr>
<?php
if ((isset($point_mondial_relay) && $point_mondial_relay)) {
?>
<tr>
<td width="60%" style="text-align: left"><?php _e('Point Mondial Relay', 'mondialrelay-wordpress') ?></td>
<td width="40%" style="text-align: right"><strong><?php echo $point_mondial_relay ?></strong></td>
</tr>
<?php
} else {
?>
<tr>
<td width="60%" style="text-align: left"><?php _e('Livraison domicile', 'mondialrelay-wordpress') ?></td>
<td width="40%" style="text-align: right"><strong><?php echo $mondial_relay_shipping_code ?></strong></td>
</tr>
<?php
}
?>
<tr>
<td width="60%" style="text-align: left"><?php _e('Statut', 'mondialrelay-wordpress') ?></td>
<td width="40%" style="text-align: right"><strong><?php echo $expedition_status ?></strong></td>
</tr>
</tbody>
</table>
<?php
// Get the global parameters of Mondial Relay account
$params_compte = class_MRWP_order::get_params_compte();
// Get the Mondial Relay point
if ((isset($point_mondial_relay) && $point_mondial_relay)) {
$explode_id_mondial_relay = explode('-', $point_mondial_relay);
$liv_rel_pays_mondial_relay = $explode_id_mondial_relay[0];
} else {
// Get the recipient parameters
$params_destinataire = class_MRWP_order::get_params_destinataire($order_id);
$params_destinataire['_shipping_langage'] = class_MRWP_helpers::get_langue($params_destinataire['_shipping_country']);
$liv_rel_pays_mondial_relay = $params_destinataire['_shipping_langage'];
}
// SOAP
try{
$client = new SoapClient(class_MRWP_main::MONDIALRELAY_WEBSERVICE);
} catch(Exception $e){
$debug_except .= $e;
$client = '';
}
$params = array(
'Enseigne' => $params_compte['mondialrelay_code_client'],
'Expeditions' => $expedition_num,
'Langue' => $liv_rel_pays_mondial_relay,
);
// Generation of the security key
$code = implode("", $params);
$code .= $params_compte['mondialrelay_cle_privee'];
$params["Security"] = strtoupper(md5($code));
try{
if ($client == '') {
$callback = 789;
} else {
$etiquette = $client->WSI3_GetEtiquettes($params)->WSI3_GetEtiquettesResult;
$callback = $etiquette->STAT;
}
} catch(Exception $e){
$debug_except .= $e;
$callback = 789;
}
if ($callback == 0) {
// Colis tracking
add_thickbox();
// Format 10x15
//$etiquette->URL_PDF_10x15 = str_replace('A4', '10x15', $etiquette->URL_PDF_A4);
?>
<p style="text-align:center">
<a class="button button-default" target="_blank" href="https://www.mondialrelay.fr/<?php echo $etiquette->URL_PDF_A4 ?>">
<?php _e('tiquette A4', 'mondialrelay-wordpress') ?>
</a>
<a class="button button-default" target="_blank" href="https://www.mondialrelay.fr/<?php echo $etiquette->URL_PDF_A5 ?>">
<?php _e('tiquette A5', 'mondialrelay-wordpress') ?>
</a>
</p>
<p style="text-align:center">
<a class="button button-default" target="_blank" href="https://www.mondialrelay.fr/<?php echo $etiquette->URL_PDF_10x15 ?>">
<?php _e('tiquette 10x15', 'mondialrelay-wordpress') ?>
</a>
</p>
<p style="text-align:center">
<a href="#TB_inline?width=600&height=420&inlineId=mondial_relay_tracking_thickbox" class="button button-default thickbox mondialrelay-tracking-button" title="<?php _e("Suivi d'expdition", 'mondialrelay-wordpress') ?>" data-order="<?php echo $order_id ?>" data-expedition="<?php echo $expedition_num ?>" data-langue="<?php echo $liv_rel_pays_mondial_relay ?>">
<?php _e("Suivi", 'mondialrelay-wordpress') ?>
</a>
</p>
<?php require_once dirname(__FILE__) . '/parts/MRWP-admin-tracking-view.php'; ?>
<?php
}
else { ?>
<p style="color: rgb(255,84,96);">
<?php _e("Erreur", 'mondialrelay-wordpress')?> <?php echo $callback ?>
</p>
<?php }
}
// No Mondial Relay expedition for this order
else {
// Get the weight of the order, WC_Order is a standard WooCommerce Class
$mondial_relay_parcel_weight = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Parcel Weight');
// Get assurance
$assurance = get_option('mondialrelay_assurance', class_MRWP_main::ASSURANCE);
// View
add_thickbox();
$data = array(
'ModeCol' => class_MRWP_main::MODE_COL,
'ModeLiv' => $mondial_relay_shipping_code,
'Poids' => $mondial_relay_parcel_weight,
'Assurance' => $assurance,
);
$this->actions_mr_meta_box_create_view($order_id, $data);
}
}
else { ?>
<em>
<?php _e("Cette commande n'utilise pas Mondial Relay", "mondialrelay-wordpress") ?>
</em>
<?php
}
}
// Mondial Relay creation of expedition view
function actions_mr_meta_box_create_view($order_id, $data) {
?>
<div style="text-align: center">
<a href="#TB_inline?width=600&height=420&inlineId=mondial_relay_expedition_thickbox" class="button button-default thickbox" title="<?php _e('Crer une expdition Mondial Relay', 'mondialrelay-wordpress') ?>"><?php _e("Crer une expdition", "mondialrelay-wordpress") ?></a>
</div>
<div id="mondial_relay_expedition_thickbox" style="display:none;">
<div id="mr-notif" style="font-size: 13px; display:none"></div>
<div id="mr-text" style="display: none; text-align: center; margin-top: 20px;"><?php _e('Veuillez patienter pendant le rechargement de la page...', 'mondialrelay-wordpress') ?></div>
<div id="mr-form">
<h3><?php _e('Paramtres', 'mondialrelay-wordpress') ?></h3>
<table class="form-table mrwp-table">
<tbody>
<!-- Shipping code chosen by the client -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="ModeLiv"><?php _e('Mode de livraison', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Le mode de livraison de colis', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<?php echo $data['ModeLiv'] ?>
</td>
</tr>
<!-- WooCommerce Expedition Number -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="NDossier"><?php _e('Numro de dossier', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Numro de commande WooCommerce', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<?php echo $order_id ?>
</td>
</tr>
<!-- Weight -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="Poids"><?php _e('Poids', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('En grammes', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<input name="Poids" id="Poids" type="number" value="<?php echo $data['Poids'] ?>" placeholder="<?php _e('Obligatoire', 'mondialrelay-wordpress') ?>" maxlength="7" required="required">
</td>
</tr>
<!-- Total packages number -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="NbColis"><?php _e('Nombre de colis', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Nombre de colis de l\'expdition (limit 1 pour l\'offre Start)', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<input type="number" value="1" name="NbColis" id="NbColis" placeholder="<?php _e('Obligatoire', 'mondialrelay-wordpress') ?>" maxlength="2" required="required">
</td>
</tr>
<!-- Expedition Value -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="Exp_Valeur"><?php _e('Valeur de l\'expdition', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Valeur de l\'expdition, en centimes dans la devise', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<input type="number" name="Exp_Valeur" id="Exp_Valeur" placeholder="<?php _e('Facultatif', 'mondialrelay-wordpress') ?>" maxlength="7">
</td>
</tr>
<!-- Insurance -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="Assurance"><?php _e("Assurance", 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e("Le niveau d'assurance pour cette livraison", 'mondialrelay-wordpress'); ?>"></span>
</th>
<td>
<select name="Assurance" id="Assurance" required="required">
<option value="" disabled><?php _e('Choisir', 'mondialrelay-wordpress') ?></option>
<option value="0" <?php if ($data['Assurance'] == 0) echo 'selected'; ?>><?php _e("0 : Sans assurance", 'mondialrelay-wordpress') ?></option>
<option value="1" <?php if ($data['Assurance'] == 1) echo 'selected'; ?>><?php _e("1 : Assurance complmentaire N1", 'mondialrelay-wordpress') ?></option>
<option value="2" <?php if ($data['Assurance'] == 2) echo 'selected'; ?>><?php _e("2 : Assurance complmentaire N2", 'mondialrelay-wordpress') ?></option>
<option value="3" <?php if ($data['Assurance'] == 3) echo 'selected'; ?>><?php _e("3 : Assurance complmentaire N3", 'mondialrelay-wordpress') ?></option>
<option value="4" <?php if ($data['Assurance'] == 4) echo 'selected'; ?>><?php _e("4 : Assurance complmentaire N4", 'mondialrelay-wordpress') ?></option>
<option value="5" <?php if ($data['Assurance'] == 5) echo 'selected'; ?>><?php _e("5 : Assurance complmentaire N5", 'mondialrelay-wordpress') ?></option>
</select>
</td>
</tr>
<!-- Information -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="Instructions"><?php _e('Instructions', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Instructions complmentaires', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<textarea name="Instructions" id="Instructions" cols="31" rows="1" maxlength="31" style="resize: none" placeholder="<?php _e('Facultatif', 'mondialrelay-wordpress') ?>"></textarea>
</td>
</tr>
</tbody>
</table>
<hr>
<div style="text-align:center">
<a href="#" id="create-expedition" class="button save_order button-primary" data-order-id="<?php echo $order_id ?>">
<?php _e('Crer une expdition', 'mondialrelay-wordpress') ?>
</a>
</div>
</div>
</div>
<?php
}
// Javascript script for the creation of the Mondial Relay expedition
function expedition_javascript() { ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('#create-expedition').off('click').on('click', function(e) {
e.preventDefault();
var th = jQuery(this);
var data = {
'action': 'expedition',
'order': th.attr('data-order-id'),
'Poids': jQuery('#Poids').val(),
'Assurance' : jQuery('#Assurance').val(),
'NbColis': jQuery('#NbColis').val(),
'Exp_Valeur': jQuery('#Exp_Valeur').val(),
'Montage': jQuery('#Montage').val(),
'Instructions': jQuery('#Instructions').val(),
};
$.post(ajaxurl, data, function(response) {
if (response != 0) {
var expedition = <?php echo __("'L\'expdition n\'a pas pu tre cre'", 'mondialrelay-wordpress') ?>;
var erreur = <?php echo __("'Erreur'", 'mondialrelay-wordpress') ?>;
jQuery('#mr-notif').addClass('update-nag').css({ "margin": "0", "display": "block" }).html("<strong>"+expedition+"</strong><br>"+erreur+" "+response).show();
}
else {
var expedition = <?php echo __("'L\'expdition a t cre'", 'mondialrelay-wordpress') ?>;
jQuery('#mr-notif').addClass('updated').css({ "padding": "11px 15px" }).html("<strong>"+expedition+"</strong>").show();
jQuery('#mr-form').hide();
jQuery('#mr-text').show();
window.location.reload();
}
console.log(response);
});
});
});
</script>
<?php }
// Expedition creation in a Mondial Relay order (AJAX)
function expedition_callback() {
global $wpdb;
$prefixe = $wpdb->prefix;
// Get the debug mode
$mondialrelay_debug = get_option('mondialrelay_debug', class_MRWP_main::DEBUG);
// Get the order number
$order_id = intval( $_POST['order'] );
// Get the Mondial Relay parameters
$params_compte = class_MRWP_order::get_params_compte();
// Mondial Relay WebService
$client = new SoapClient(class_MRWP_main::MONDIALRELAY_WEBSERVICE);
// Get the Mondial Relay point
$id_mondial_relay = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Parcel Shop ID');
if ((isset($id_mondial_relay) && $id_mondial_relay)) {
$explode_id_mondial_relay = explode('-', $id_mondial_relay);
$params_livraison = class_MRWP_order::get_params_livraison();
$params_livraison['liv_rel_pays_mondial_relay'] = $explode_id_mondial_relay[0];
$params_livraison['liv_rel_mondial_relay'] = $explode_id_mondial_relay[1];
} else {
$params_livraison['liv_rel_pays_mondial_relay'] = '';
$params_livraison['liv_rel_mondial_relay'] = '';
}
// Get the sender parameters
$params_expediteur = class_MRWP_order::get_params_expediteur();
// Get the recipient parameters
$params_destinataire = class_MRWP_order::get_params_destinataire($order_id);
// Hook to change the expedition address
$params_destinataire = apply_filters( 'mrwp_chg_expe_add', $params_destinataire, $order_id);
// Remove accents
foreach($params_destinataire as $key => $champ) {
$params_destinataire[$key] = remove_accents($champ);
}
// Split adress if more than 32 characters
$numchar = strlen($params_destinataire['_shipping_address_1']);
if ($numchar > 32 ) {
$numcut = strrpos($params_destinataire['_shipping_address_1'],' ', -($numchar - 30));
$params_destinataire['_shipping_address_2'] = substr($params_destinataire['_shipping_address_1'], $numcut + 1, $numchar);
$params_destinataire['_shipping_address_1'] = substr($params_destinataire['_shipping_address_1'], 0, $numcut);
}
if (strlen($params_destinataire['_shipping_company']) > 32 ) {
$params_destinataire['_shipping_company'] = substr($params_destinataire['_shipping_company'], 0, 31);
}
// Remove quotes (') on Dest_Ad3 parameter for the Mondial Relay webservice
$params_destinataire['_shipping_address_1'] = str_replace("'", " ", $params_destinataire['_shipping_address_1']);
// Remove CRLF codes and specials characters for the Mondial Relay webservice
$elim = array("'", "", "", "", "", "", "(", ")", "+", "''", '"', "'");
$params_destinataire['_shipping_full_name'] = str_replace("
","", $params_destinataire['_shipping_full_name']);
$params_destinataire['_shipping_full_name'] = str_replace("
","", $params_destinataire['_shipping_full_name']);
$params_destinataire['_shipping_full_name'] = str_replace($elim, " ", $params_destinataire['_shipping_full_name']);
$params_destinataire['_shipping_company'] = str_replace("
","", $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_company'] = str_replace("
","", $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_company'] = str_replace(""," ", $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_company'] = str_replace($elim, " ", $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_company'] = preg_replace("/@/", ' ', $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_address_1'] = str_replace("
","", $params_destinataire['_shipping_address_1']);
$params_destinataire['_shipping_address_1'] = str_replace("
","", $params_destinataire['_shipping_address_1']);
$params_destinataire['_shipping_address_1'] = str_replace($elim, " ", $params_destinataire['_shipping_address_1']);
$params_destinataire['_shipping_address_2'] = str_replace("
","", $params_destinataire['_shipping_address_2']);
$params_destinataire['_shipping_address_2'] = str_replace("
","", $params_destinataire['_shipping_address_2']);
$params_destinataire['_shipping_address_2'] = str_replace($elim, " ", $params_destinataire['_shipping_address_2']);
$params_destinataire['_shipping_city'] = str_replace("
","", $params_destinataire['_shipping_city']);
$params_destinataire['_shipping_city'] = str_replace("
","", $params_destinataire['_shipping_city']);
$params_destinataire['_shipping_city'] = str_replace($elim, " ", $params_destinataire['_shipping_city']);
$params_destinataire['_shipping_postcode'] = str_replace("
","", $params_destinataire['_shipping_postcode']);
$params_destinataire['_shipping_postcode'] = str_replace("
","", $params_destinataire['_shipping_postcode']);
$params_destinataire['_shipping_postcode'] = str_replace($elim, " ", $params_destinataire['_shipping_postcode']);
$params_destinataire['_shipping_country'] = str_replace("
","", $params_destinataire['_shipping_country']);
$params_destinataire['_shipping_country'] = str_replace("
","", $params_destinataire['_shipping_country']);
$params_destinataire['_shipping_country'] = str_replace($elim, " ", $params_destinataire['_shipping_country']);
// Get the order parameters
$params_commande =class_MRWP_order::get_params_commande();
$params_commande['ModeCol'] = class_MRWP_main::MODE_COL;
$params_commande['ModeLiv'] = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Shipping Code');
$params_commande['NDossier'] = $order_id;
$params_commande['NClient'] = apply_filters( 'mrwp_add_nclient', $params_commande['NClient']);
// Get assurance
$assurance = intval( $_POST['Assurance'] );
// Get the collect point parameters
$params_collecte = class_MRWP_order::get_params_collecte();
// Expedition parameters
$params = array(
'Enseigne' => $params_compte['mondialrelay_code_client']
,'ModeCol' => $params_commande['ModeCol']
,'ModeLiv' => $params_commande['ModeLiv']
,'NDossier' => $params_commande['NDossier']
,'NClient' => $params_commande['NClient']
,'Expe_Langage' => $params_expediteur['mondialrelay_vendeur_langage']
,'Expe_Ad1' => $params_expediteur['mondialrelay_vendeur_adresse1']
,'Expe_Ad2' => $params_expediteur['mondialrelay_vendeur_adresse2']
,'Expe_Ad3' => $params_expediteur['mondialrelay_vendeur_adresse3']
,'Expe_Ad4' => $params_expediteur['mondialrelay_vendeur_adresse4']
,'Expe_Ville' => $params_expediteur['mondialrelay_vendeur_ville']
,'Expe_CP' => $params_expediteur['mondialrelay_vendeur_cp']
,'Expe_Pays' => $params_expediteur['mondialrelay_vendeur_pays']
,'Expe_Tel1' => $params_expediteur['mondialrelay_vendeur_tel']
,'Expe_Tel2' => $params_expediteur['mondialrelay_vendeur_tel2']
,'Expe_Mail' => $params_expediteur['mondialrelay_vendeur_email']
,'Dest_Langage' => $params_destinataire['_shipping_langage']
,'Dest_Ad1' => $params_destinataire['_shipping_full_name']
,'Dest_Ad2' => $params_destinataire['_shipping_company']
,'Dest_Ad3' => $params_destinataire['_shipping_address_1']
,'Dest_Ad4' => $params_destinataire['_shipping_address_2']
,'Dest_Ville' => $params_destinataire['_shipping_city']
,'Dest_CP' => $params_destinataire['_shipping_postcode']
,'Dest_Pays' => $params_destinataire['_shipping_country']
,'Dest_Tel1' => $params_destinataire['_billing_phone']
,'Dest_Mail' => $params_destinataire['_billing_email']
,'Poids' => $params_commande['Poids']
,'Longueur' => $params_commande['Longueur']
,'Taille' => $params_commande['Taille']
,'NbColis' => $params_commande['NbColis']
,'CRT_Valeur' => $params_commande['CRT_Valeur']
,'CRT_Devise' => $params_commande['CRT_Devise']
,'Exp_Valeur' => $params_commande['Exp_Valeur']
,'Exp_Devise' => $params_commande['Exp_Devise']
,'COL_Rel_Pays' => $params_collecte['col_rel_pays_mondial_relay']
,'COL_Rel' => $params_collecte['col_rel_mondial_relay']
,'LIV_Rel_Pays' => $params_livraison['liv_rel_pays_mondial_relay']
,'LIV_Rel' => $params_livraison['liv_rel_mondial_relay']
,'TAvisage' => $params_commande['TAvisage']
,'TReprise' => $params_commande['TReprise']
,'Montage' => $params_commande['Montage']
,'TRDV' => $params_commande['TRDV']
//,'Instructions' => $params_commande['Instructions']
,'Instructions' => ''
,'Assurance' => $assurance
);
// Generation of the security key
$code = implode("", $params);
$code .= $params_compte['mondialrelay_cle_privee'];
$params["Security"] = strtoupper(md5($code));
// Expedition creation
// Si le num d'exp existe dj, alors message d'erreur, sinon cration d'expdition
$expe_exist = class_MRWP_db::get_meta_champ($order_id, 'ExpeditionNum');
if ($expe_exist) {
$callback = 421;
} else {
try{
$expedition = $client->WSI2_CreationExpedition($params)->WSI2_CreationExpeditionResult;
$callback = $expedition->STAT;
} catch(Exception $e){
$debug_except .= $e;
$callback = 789;
}
}
// Statut code
if ($callback != 0) {
echo $callback . '<br>' . class_MRWP_helpers::statut($callback);
if ($mondialrelay_debug) {
if ($callback == 789) {
class_MRWP_helpers::VarPrint($debug_except);
}
class_MRWP_helpers::VarPrint($params);
}
}
elseif ($callback == 0) {
// Add the Mondial Relay expedition paramaters in the database
$champs_bdd = class_MRWP_order::get_expedition_champs($expedition, $params_commande['NbColis']);
class_MRWP_db::insert_meta_champs($order_id, $champs_bdd);
// Get the Mondial Relay email
$email = class_MRWP_order::get_params_emails($order_id);
// Hook creation after db updated
do_action('MRWP_after_expedition_creation', $order_id);
// Update the checkout status
$checkout_status = get_option( 'mondialrelay_state_order', '' );
if ($checkout_status) {
$order = new WC_Order($order_id);
if (!empty($order)) {
$order->update_status($checkout_status);
}
}
// br in html
$email['message'] = nl2br($email['message']);
// Check if email send is activated
if ($email['send'] == 1) {
$destinataire = $params_destinataire['_billing_email'];
// Send the Mondial Relay tracking email to the client
$mail = wc_mail($destinataire, $email['sujet'], $email['message']);
}
// Hook creation after db updated
do_action('MRWP_after_order_status_updated', $order_id);
}
die();
}
// Javascript script for the tracking of the Mondial Relay expedition
function tracking_javascript() { ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('.mondialrelay-tracking-button').on('click', function(e) {
var th = jQuery(this);
var order = th.attr('data-order');
var expedition = th.attr('data-expedition');
var langue = th.attr('data-langue');
var data = {
'action': 'tracking',
'order': order,
'expedition': expedition,
'langue': langue
};
$.post(ajaxurl, data, function(response) {
var obj = JSON.parse(response);
//console.log(obj);
var jsonObj = JSON.parse(obj.content);
var jsonPretty = JSON.stringify(jsonObj, null, ' ');
if (obj.response) {
jQuery('#mondial_relay_tracking_notif').addClass('updated').css({ "padding": "11px 15px" }).html(obj.notification).show();
jQuery('#mondial_relay_tracking_Libelle01').html('<strong>' + obj.content.Libelle01 + '</strong>');
jQuery('#mondial_relay_tracking_Relais_Libelle').html('<strong>' + obj.content.Relais_Libelle + '</strong>');
jQuery('#mondial_relay_tracking_Relais_Num').html('<strong>' + obj.content.Relais_Num + '</strong>');
jQuery('#mondial_relay_tracking_Libelle02').html('<strong>' + obj.content.Libelle02 + '</strong>');
var tracing_view = '<table class="wp-list-table widefat fixed striped"><tbody>';
for (var i = 0; i < tracing.length; i++){
var table = tracing[i];
tracing_view += '<tr><td colspan="2"><strong>vnement ' + i + '</strong></td></tr>';
for (var key in table) {
var tracing_libelle = key.replace('Tracing_', '');
tracing_view += '<tr>';
tracing_view += '<td width="60%" style="text-align: left">' + tracing_libelle + '</td>';
tracing_view += '<td width="40%" style="text-align: right"><strong>' + table[key] + '</strong></td>';
tracing_view += '</tr>';
}
}
tracing_view += '</tbody></table>';
//console.log(tracing_view);
jQuery('#mondial_relay_tracking_tracing').html(tracing_view);
jQuery('#mondial_relay_tracking_content').show();
}
else {
jQuery('#mondial_relay_tracking_notif').addClass('update-nag').css({ "display": "block" }).html(obj.notification).show();
}
if (obj.debug) {
jQuery('#mondial_relay_tracking_debug').html(jsonPretty);
}
//console.log(response);
});
});
});
</script>
<?php }
// Expedition tracking of a Mondial Relay expedition (AJAX)
function tracking_callback() {
// Get the debug mode
$mondialrelay_debug = get_option('mondialrelay_debug', class_MRWP_main::DEBUG);
// Get the Mondial Relay parameters
$params_compte = class_MRWP_order::get_params_compte();
// Get the shipping parameters
$expedition = $_POST['expedition'];
$order_id = intval( $_POST['order'] );
$shop_location = wc_get_base_location();
$langue = class_MRWP_helpers::get_langue( $shop_location['country'] );
// SOAP
$client = new SoapClient(class_MRWP_main::MONDIALRELAY_WEBSERVICE);
$params = array(
'Enseigne' => $params_compte['mondialrelay_code_client'],
'Expedition' => $expedition,
'Langue' => $langue,
);
// Generation of the security key
$code = implode("", $params);
$code .= $params_compte['mondialrelay_cle_privee'];
$params["Security"] = strtoupper(md5($code));
try{
$tracking = $client->WSI2_TracingColisDetaille($params)->WSI2_TracingColisDetailleResult;
$callback = $tracking->STAT;
} catch(Exception $e){
$debug_except .= $e;
$callback = 789;
}
if ($callback == 0) {
$response = 1;
$notification = 'Succs';
// Correct tracking result
} elseif ($callback == 80 || $callback == 81 || $callback == 82){
$response = 1;
$notification = $callback . ' : ' . class_MRWP_helpers::statut($callback );
update_post_meta($order_id, 'ExpeditionStatus', $callback);
update_post_meta($order_id, 'ExpeditionStatusDate', time());
// Update the status
if ( 82 == $callback ) {
$order_delivered_status = get_option( 'mondialrelay_state_order_delivered', 0 );
$order = new WC_Order($order_id);
if ( '' != $order_delivered_status ) {
$order->update_status( $order_delivered_status );
}
}
// Incorrect tracking result
} elseif ($callback == 83){
$response = 0;
$notification = $callback . ' : ' . class_MRWP_helpers::statut($callback );
update_post_meta($order_id, 'ExpeditionStatus', $callback);
update_post_meta($order_id, 'ExpeditionStatusDate', time());
// Error
} else {
$response = 0;
$notification = $callback . ' : ' . class_MRWP_helpers::statut($callback );
if ($mondialrelay_debug) {
$notification = $notification . '<br><br>' . print_r($params, true);
}
}
$debug = 0;
if ($mondialrelay_debug) {
$debug = 1;
}
$data = array(
'response' => $response,
'notification' => $notification,
'content' => json_encode( $tracking ),
'debug' => $debug,
);
echo json_encode( $data );
die();
}
} ?>
Did this file decode correctly?
Original Code
<?php
// Admin part of the plugin
// Defines the plugin name, version, and two examples hooks for how to enqueue the admin-specific stylesheet and JavaScript
class class_MRWP_admin {
// Privaye var
private $plugin_name; // name of the plugin
private $version; // current version of the plugin
private $current_version; // current version of the plugin
private $menu_position; // menu position of the plugin
// Initialize the class and set its properties.
public function __construct($plugin_name, $version, $current_version, $menu_position) {
$this->plugin_name = $plugin_name;
$this->version = $version;
$this->current_version = $current_version;
$this->menu_position = $menu_position;
}
// Register the stylesheets for the admin area
public function enqueue_styles() {
wp_enqueue_style( 'woocommerce_admin', plugins_url().'/' . class_MRWP_main::WOOCOMMERCE_FOLDER . '/assets/css/admin.css', $this->version, 'all' );
wp_enqueue_style( 'mondialrelay_admin', plugin_dir_url(dirname(__FILE__)).'admin/css/MRWP-admin.css', $this->version, 'all' );
}
// Register the JavaScript for the admin area
public function enqueue_scripts( $hook_suffix ) {
// WooCommerce scripts
$this->woocommerce_scripts();
// Mondial Relay scripts
wp_register_script( 'jquery_validate', plugin_dir_url(dirname(__FILE__)).'admin/js/jquery.validate.min.js', array( 'jquery'));
wp_enqueue_script( 'jquery_validate', $this->version, false);
wp_register_script( 'mondialrelay_admin_validate', plugin_dir_url(dirname(__FILE__)).'admin/js/MRWP-admin.js', array( 'jquery'));
// Localize the script with new data
$translation_array = array(
'message1' => __(' < Entrez votre code client', 'mondialrelay-wordpress'),
'message2' => __(' < Votre code client doit tre de 8 caractres', 'mondialrelay-wordpress'),
'message3' => __(' < Entrez votre code marque', 'mondialrelay-wordpress'),
'message4' => __(' < Entrez votre cl priv', 'mondialrelay-wordpress'),
'message5' => __(' < Entrez votre niveau d\'assurance', 'mondialrelay-wordpress'),
'message6' => __(' < Entrez un nombre valide', 'mondialrelay-wordpress'),
'message7' => __(' < Entrez votre nom d\'expditeur', 'mondialrelay-wordpress'),
'message8' => __(' < Votre nom d\'expditeur doit contenir au maximum 32 caractres', 'mondialrelay-wordpress'),
'message9' => __(' < Votre complment d\'expditeur doit contenir au maximum 32 caractres', 'mondialrelay-wordpress'),
'message10' => __(' < Entrez votre rue', 'mondialrelay-wordpress'),
'message11' => __(' < Votre rue doit contenir au maximum 32 caractres', 'mondialrelay-wordpress'),
'message12' => __(' < Entrez votre code postal', 'mondialrelay-wordpress'),
'message13' => __(' < Votre code postal doit contenir au maximum 5 caractres', 'mondialrelay-wordpress'),
'message14' => __(' < Entrez votre ville', 'mondialrelay-wordpress'),
'message15' => __(' < Votre ville doit contenir au maximum 26 caractres', 'mondialrelay-wordpress'),
'message16' => __(' < Entrez votre pays', 'mondialrelay-wordpress'),
'message17' => __(' < Votre pays doit contenir au maximum 2 caractres', 'mondialrelay-wordpress'),
'message18' => __(' < Entrez votre numro de tlphone', 'mondialrelay-wordpress'),
'message19' => __(' < Votre numro de tlphone doit contenir au maximum 13 caractres', 'mondialrelay-wordpress'),
'message20' => __(' < Votre adresse e-mail doit contenir au maximum 70 caractres', 'mondialrelay-wordpress'),
'message21' => __(' ^ Entrez un sujet', 'mondialrelay-wordpress'),
'message22' => __(' ^ Entrez le contenu de votre email', 'mondialrelay-wordpress'),
'message23' => __(' < Choisissez la position du menu du plugin Mondial Relay', 'mondialrelay-wordpress'),
'message24' => __(' < Votre complment d\'adresse doit contenir au maximum 32 caractres', 'mondialrelay-wordpress'),
);
wp_localize_script( 'mondialrelay_admin_validate', 'MRWP_i18n', $translation_array );
// @todo Refactoring Revoir tous les wp_register_script() et wp_enqueue_script() qui ne sont pas corrects
wp_enqueue_script( 'mondialrelay_admin_validate', $this->version, false);
// Only enqueue the zones export script in the appropriate page
if ( 'toplevel_page_wp-mondialrelay' == $hook_suffix ) {
wp_register_script( 'mondialrelay_zones', plugin_dir_url( __DIR__ ) . 'admin/js/shipping-zones.js', array( 'jquery' ), $this->version );
wp_enqueue_script( 'mondialrelay_zones' ) ;
}
}
/**
* Enqueue JS for Ajax WP_List_Table
*/
public function enqueue_list_script() {
wp_register_script( 'mondialrelay_admin_mass_shipping', plugin_dir_url(dirname(__FILE__)). 'admin/js/list-table.js', array( 'jquery', 'jquery-ui-datepicker' ) );
wp_enqueue_script( 'mondialrelay_admin_mass_shipping', $this->version, false);
// Date picker
wp_enqueue_script( 'jquery-ui-datepicker' );
/* Choose jQuery UI theme on this page
* https://jqueryui.com/themeroller/#!zThemeParams=5d00008000ea05000000000000003d8888d844329a8dfe02723de3e5701258a13d5ba490adca99e4a02bf259c3083bccd292fbc7a815b30f470ff7864f8c0d0abbfd0926063d14faae19f29b086c2f4cf156a8205f7f8a4665545a5673e9f68749a54ab4746c69d599dce963fc3aa65b2c0af8483da4f905056d9752840f949d1956aecdd062dd566cab69194f70740c7a8eb43b906c3dfb317e62615319e0ccabb3fa3370a66b6d22a53a0ae6b209b465064ce1462b9be2cf60c233a80f57f75a7c2f469e6b8439ad8c1db376bb6a8cdfd2627f4334b44198e955e4256b0a8a6ee6d2f45da7567e0f7aa22c9d81d684db86e18ece2497400fe0f135cc38bfd1e55939aeda6c2ecfdab826c6779b110967ae1299dff254dcd78dd5b26dd2df26cffa81bbc523debff64e26be65e6a620c045190e203904e9d81bcea2f4834a2016ed531ec391294e7673cab97b38ffe66c2dc20e96b09790d2ca260d9b778eb49c95cf80aece999855d79bbd8568647998fac2fcbce76524897433dc876aa689b6bc8494075f7ec0a68f66d3f2417247e5b022db641f3a79f968edd1bf078f7f6b79d5faf38bb47379b04163fb66f4b32fa24b8722298ca1f9505a194f03142c8f3dc1affe3191d6
*
* Theme name goes after 1.12.1/themes/
* Eg 1.12.1/themes/flick/
*/
wp_enqueue_style( 'mrwp-jquery-ui','https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/flick/jquery-ui.css', false, '1.12.1', false );
}
// Register the WooCommerce JavaScript for the admin area
public function woocommerce_scripts() {
// Register scripts
wp_register_script( 'woocommerce_admin', plugins_url().'/' . class_MRWP_main::WOOCOMMERCE_FOLDER . '/assets/js/admin/woocommerce_admin.min.js', array( 'jquery', 'jquery-blockui', 'jquery-ui-sortable', 'jquery-ui-widget', 'jquery-ui-core', 'jquery-tiptip' ), WC_VERSION );
wp_register_script( 'jquery-blockui', plugins_url().'/' . class_MRWP_main::WOOCOMMERCE_FOLDER . '/assets/js/jquery-blockui/jquery.blockUI.min.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'jquery-tiptip', plugins_url().'/' . class_MRWP_main::WOOCOMMERCE_FOLDER . '/assets/js/jquery-tiptip/jquery.tipTip.min.js', array( 'jquery' ), WC_VERSION,true );
// Enqueue scripts
//wp_enqueue_script( 'iris' );
//wp_enqueue_script( 'woocommerce_admin' );
}
// Show row meta on the plugin screen
public static function plugin_row_meta( $links, $file ) {
if ( strpos( $file, class_MRWP_main::PLUGIN_NAME ) !== false ) {
$new_links = array(
'<a href="' . class_MRWP_main::DOCUMENTATION . '" target="_blank">' . __('Documentation', 'mondialrelay-wordpress') . '</a>',
'<a href="' . class_MRWP_main::CLIENT . '" target="_blank">' . __('Espace client', 'mondialrelay-wordpress') . '</a>',
);
$links = array_merge( $links, $new_links );
}
return $links;
}
// Add Mondial Relay menu
public function MondialRelayMenu() {
$mondialrelay_menu_position = get_option( 'mondialrelay_menu_position', class_MRWP_main::MENU_POSITION );
add_menu_page(
__('Mondial Relay - Mondial Relay pour WordPress', 'mondialrelay-wordpress'),
__('Mondial Relay', 'mondialrelay-wordpress'),
'manage_woocommerce',
'wp-mondialrelay',
array($this, 'MondialRelayPage'),
'dashicons-location',
$mondialrelay_menu_position
);
$pagename = add_submenu_page(
'wp-mondialrelay',
__('Cration en masse - Mondial Relay pour WordPress', 'mondialrelay-wordpress'),
__('Cration en masse', 'mondialrelay-wordpress'),
'manage_woocommerce',
'wp-mondialrelay-mass-expeditions',
array( $this, 'MondialRelayMassShipping' )
);
// Enqueue JS for this page only
// @see https://wordpress.stackexchange.com/a/76420
add_action( 'load-' . $pagename, array( $this, 'enqueue_list_script' ) );
$pagename = add_submenu_page(
'wp-mondialrelay',
__('Expditions - Mondial Relay pour WordPress', 'mondialrelay-wordpress'),
__('Expditions', 'mondialrelay-wordpress'),
'manage_woocommerce',
'wp-mondialrelay-expeditions',
array( $this, 'MondialRelayShipping' )
);
// Enqueue JS for this page only
add_action( 'load-' . $pagename, array( $this, 'enqueue_list_script' ) );
add_submenu_page(
'wp-mondialrelay',
__('Maintenance - Mondial Relay pour WordPress', 'mondialrelay-wordpress'),
__('Maintenance', 'mondialrelay-wordpress'),
'manage_woocommerce',
'wp-mondialrelay-maintenance',
array($this, 'MondialRelayMaintenance')
);
}
// Notification when the plugin has an update available
public function notificationMenu() {
if (false !== ($contents = @file_get_contents($this->current_version))) {
$current = file_get_contents($this->current_version);
} else {
$current = $this->version;
}
if (version_compare($this->version, $current, '<')) {
$submenu['wp-mondialrelay'][5][0] .= "<span class='update-plugins count-1'><span class='update-count'>1</span></span>";
$menu[$this->menu_position][0] .= "<span class='update-plugins count-1'><span class='update-count'>1</span></span>";
}
}
// Mondial Relay options page
function MondialRelayPage($settings) {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/parts/MRWP-admin-page.php';
}
// Expeditions listing page of Mondial Relay
function MondialRelayShipping($settings) {
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/parts/MRWP-admin-history.php';
}
// Mass Expeditions
function MondialRelayMassShipping($settings) {
require_once plugin_dir_path( __DIR__ ) . 'admin/parts/MRWP-admin-mass-shipping.php';
}
// Mondial Relay maintenance page
function MondialRelayMaintenance($settings) {
global $wpdb;
$prefixe = $wpdb->prefix;
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/parts/MRWP-admin-maintenance.php';
}
// Mondial Relay in a WooCommerce order
function actions_mr_meta_box($order_id) {
add_meta_box(
'mondialrelay_expedition_meta_box',
__( 'Mondial Relay', 'mondialrelay-wordpress' ),
array($this, 'actions_mr_meta_box_callback'),
'shop_order',
'side'
);
}
// Mondial Relay function in a WooCommerce order
function actions_mr_meta_box_callback( $order ) {
global $wpdb;
$prefixe = $wpdb->prefix;
$order_id = $order->ID;
// Check if the order uses Mondial Relay
$mondial_relay_shipping_code = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Shipping Code');
$isMR = $mondial_relay_shipping_code;
if (isset($isMR) && $isMR != 'HMR' && $isMR != '' ) {
// Display the right box
wp_nonce_field( 'actions_mr_meta_box', 'actions_mr_meta_box_nonce' );
// Check if a Mondial Relay expedition already exists
$exist_expedition = class_MRWP_db::get_meta_champ($order_id, 'ExpeditionNum', 1);
// A Mondial Relay expedition already exists for this order
if (isset($exist_expedition) && $exist_expedition) {
$expedition_num = class_MRWP_db::get_meta_champ($order_id, 'ExpeditionNum');
$expedition_statusid = class_MRWP_db::get_meta_champ($order_id, 'ExpeditionStatus');
$expedition_status = class_MRWP_helpers::etat_expedition($expedition_statusid);
// Get Mondial Relais oint if exists
$point_mondial_relay = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Parcel Shop ID');
?>
<table class="wp-list-table widefat fixed striped">
<tbody>
<tr>
<td width="60%" style="text-align: left"><?php _e('Expdition', 'mondialrelay-wordpress') ?></td>
<td width="40%" style="text-align: right"><strong><?php echo $expedition_num ?></strong></td>
</tr>
<?php
if ((isset($point_mondial_relay) && $point_mondial_relay)) {
?>
<tr>
<td width="60%" style="text-align: left"><?php _e('Point Mondial Relay', 'mondialrelay-wordpress') ?></td>
<td width="40%" style="text-align: right"><strong><?php echo $point_mondial_relay ?></strong></td>
</tr>
<?php
} else {
?>
<tr>
<td width="60%" style="text-align: left"><?php _e('Livraison domicile', 'mondialrelay-wordpress') ?></td>
<td width="40%" style="text-align: right"><strong><?php echo $mondial_relay_shipping_code ?></strong></td>
</tr>
<?php
}
?>
<tr>
<td width="60%" style="text-align: left"><?php _e('Statut', 'mondialrelay-wordpress') ?></td>
<td width="40%" style="text-align: right"><strong><?php echo $expedition_status ?></strong></td>
</tr>
</tbody>
</table>
<?php
// Get the global parameters of Mondial Relay account
$params_compte = class_MRWP_order::get_params_compte();
// Get the Mondial Relay point
if ((isset($point_mondial_relay) && $point_mondial_relay)) {
$explode_id_mondial_relay = explode('-', $point_mondial_relay);
$liv_rel_pays_mondial_relay = $explode_id_mondial_relay[0];
} else {
// Get the recipient parameters
$params_destinataire = class_MRWP_order::get_params_destinataire($order_id);
$params_destinataire['_shipping_langage'] = class_MRWP_helpers::get_langue($params_destinataire['_shipping_country']);
$liv_rel_pays_mondial_relay = $params_destinataire['_shipping_langage'];
}
// SOAP
try{
$client = new SoapClient(class_MRWP_main::MONDIALRELAY_WEBSERVICE);
} catch(Exception $e){
$debug_except .= $e;
$client = '';
}
$params = array(
'Enseigne' => $params_compte['mondialrelay_code_client'],
'Expeditions' => $expedition_num,
'Langue' => $liv_rel_pays_mondial_relay,
);
// Generation of the security key
$code = implode("", $params);
$code .= $params_compte['mondialrelay_cle_privee'];
$params["Security"] = strtoupper(md5($code));
try{
if ($client == '') {
$callback = 789;
} else {
$etiquette = $client->WSI3_GetEtiquettes($params)->WSI3_GetEtiquettesResult;
$callback = $etiquette->STAT;
}
} catch(Exception $e){
$debug_except .= $e;
$callback = 789;
}
if ($callback == 0) {
// Colis tracking
add_thickbox();
// Format 10x15
//$etiquette->URL_PDF_10x15 = str_replace('A4', '10x15', $etiquette->URL_PDF_A4);
?>
<p style="text-align:center">
<a class="button button-default" target="_blank" href="https://www.mondialrelay.fr/<?php echo $etiquette->URL_PDF_A4 ?>">
<?php _e('tiquette A4', 'mondialrelay-wordpress') ?>
</a>
<a class="button button-default" target="_blank" href="https://www.mondialrelay.fr/<?php echo $etiquette->URL_PDF_A5 ?>">
<?php _e('tiquette A5', 'mondialrelay-wordpress') ?>
</a>
</p>
<p style="text-align:center">
<a class="button button-default" target="_blank" href="https://www.mondialrelay.fr/<?php echo $etiquette->URL_PDF_10x15 ?>">
<?php _e('tiquette 10x15', 'mondialrelay-wordpress') ?>
</a>
</p>
<p style="text-align:center">
<a href="#TB_inline?width=600&height=420&inlineId=mondial_relay_tracking_thickbox" class="button button-default thickbox mondialrelay-tracking-button" title="<?php _e("Suivi d'expdition", 'mondialrelay-wordpress') ?>" data-order="<?php echo $order_id ?>" data-expedition="<?php echo $expedition_num ?>" data-langue="<?php echo $liv_rel_pays_mondial_relay ?>">
<?php _e("Suivi", 'mondialrelay-wordpress') ?>
</a>
</p>
<?php require_once dirname(__FILE__) . '/parts/MRWP-admin-tracking-view.php'; ?>
<?php
}
else { ?>
<p style="color: rgb(255,84,96);">
<?php _e("Erreur", 'mondialrelay-wordpress')?> <?php echo $callback ?>
</p>
<?php }
}
// No Mondial Relay expedition for this order
else {
// Get the weight of the order, WC_Order is a standard WooCommerce Class
$mondial_relay_parcel_weight = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Parcel Weight');
// Get assurance
$assurance = get_option('mondialrelay_assurance', class_MRWP_main::ASSURANCE);
// View
add_thickbox();
$data = array(
'ModeCol' => class_MRWP_main::MODE_COL,
'ModeLiv' => $mondial_relay_shipping_code,
'Poids' => $mondial_relay_parcel_weight,
'Assurance' => $assurance,
);
$this->actions_mr_meta_box_create_view($order_id, $data);
}
}
else { ?>
<em>
<?php _e("Cette commande n'utilise pas Mondial Relay", "mondialrelay-wordpress") ?>
</em>
<?php
}
}
// Mondial Relay creation of expedition view
function actions_mr_meta_box_create_view($order_id, $data) {
?>
<div style="text-align: center">
<a href="#TB_inline?width=600&height=420&inlineId=mondial_relay_expedition_thickbox" class="button button-default thickbox" title="<?php _e('Crer une expdition Mondial Relay', 'mondialrelay-wordpress') ?>"><?php _e("Crer une expdition", "mondialrelay-wordpress") ?></a>
</div>
<div id="mondial_relay_expedition_thickbox" style="display:none;">
<div id="mr-notif" style="font-size: 13px; display:none"></div>
<div id="mr-text" style="display: none; text-align: center; margin-top: 20px;"><?php _e('Veuillez patienter pendant le rechargement de la page...', 'mondialrelay-wordpress') ?></div>
<div id="mr-form">
<h3><?php _e('Paramtres', 'mondialrelay-wordpress') ?></h3>
<table class="form-table mrwp-table">
<tbody>
<!-- Shipping code chosen by the client -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="ModeLiv"><?php _e('Mode de livraison', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Le mode de livraison de colis', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<?php echo $data['ModeLiv'] ?>
</td>
</tr>
<!-- WooCommerce Expedition Number -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="NDossier"><?php _e('Numro de dossier', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Numro de commande WooCommerce', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<?php echo $order_id ?>
</td>
</tr>
<!-- Weight -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="Poids"><?php _e('Poids', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('En grammes', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<input name="Poids" id="Poids" type="number" value="<?php echo $data['Poids'] ?>" placeholder="<?php _e('Obligatoire', 'mondialrelay-wordpress') ?>" maxlength="7" required="required">
</td>
</tr>
<!-- Total packages number -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="NbColis"><?php _e('Nombre de colis', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Nombre de colis de l\'expdition (limit 1 pour l\'offre Start)', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<input type="number" value="1" name="NbColis" id="NbColis" placeholder="<?php _e('Obligatoire', 'mondialrelay-wordpress') ?>" maxlength="2" required="required">
</td>
</tr>
<!-- Expedition Value -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="Exp_Valeur"><?php _e('Valeur de l\'expdition', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Valeur de l\'expdition, en centimes dans la devise', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<input type="number" name="Exp_Valeur" id="Exp_Valeur" placeholder="<?php _e('Facultatif', 'mondialrelay-wordpress') ?>" maxlength="7">
</td>
</tr>
<!-- Insurance -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="Assurance"><?php _e("Assurance", 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e("Le niveau d'assurance pour cette livraison", 'mondialrelay-wordpress'); ?>"></span>
</th>
<td>
<select name="Assurance" id="Assurance" required="required">
<option value="" disabled><?php _e('Choisir', 'mondialrelay-wordpress') ?></option>
<option value="0" <?php if ($data['Assurance'] == 0) echo 'selected'; ?>><?php _e("0 : Sans assurance", 'mondialrelay-wordpress') ?></option>
<option value="1" <?php if ($data['Assurance'] == 1) echo 'selected'; ?>><?php _e("1 : Assurance complmentaire N1", 'mondialrelay-wordpress') ?></option>
<option value="2" <?php if ($data['Assurance'] == 2) echo 'selected'; ?>><?php _e("2 : Assurance complmentaire N2", 'mondialrelay-wordpress') ?></option>
<option value="3" <?php if ($data['Assurance'] == 3) echo 'selected'; ?>><?php _e("3 : Assurance complmentaire N3", 'mondialrelay-wordpress') ?></option>
<option value="4" <?php if ($data['Assurance'] == 4) echo 'selected'; ?>><?php _e("4 : Assurance complmentaire N4", 'mondialrelay-wordpress') ?></option>
<option value="5" <?php if ($data['Assurance'] == 5) echo 'selected'; ?>><?php _e("5 : Assurance complmentaire N5", 'mondialrelay-wordpress') ?></option>
</select>
</td>
</tr>
<!-- Information -->
<tr valign="top">
<th scope="row" class="titledesc">
<label for="Instructions"><?php _e('Instructions', 'mondialrelay-wordpress') ?></label>
<span class="woocommerce-help-tip" data-tip="<?php _e('Instructions complmentaires', 'mondialrelay-wordpress') ?>"></span>
</th>
<td>
<textarea name="Instructions" id="Instructions" cols="31" rows="1" maxlength="31" style="resize: none" placeholder="<?php _e('Facultatif', 'mondialrelay-wordpress') ?>"></textarea>
</td>
</tr>
</tbody>
</table>
<hr>
<div style="text-align:center">
<a href="#" id="create-expedition" class="button save_order button-primary" data-order-id="<?php echo $order_id ?>">
<?php _e('Crer une expdition', 'mondialrelay-wordpress') ?>
</a>
</div>
</div>
</div>
<?php
}
// Javascript script for the creation of the Mondial Relay expedition
function expedition_javascript() { ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('#create-expedition').off('click').on('click', function(e) {
e.preventDefault();
var th = jQuery(this);
var data = {
'action': 'expedition',
'order': th.attr('data-order-id'),
'Poids': jQuery('#Poids').val(),
'Assurance' : jQuery('#Assurance').val(),
'NbColis': jQuery('#NbColis').val(),
'Exp_Valeur': jQuery('#Exp_Valeur').val(),
'Montage': jQuery('#Montage').val(),
'Instructions': jQuery('#Instructions').val(),
};
$.post(ajaxurl, data, function(response) {
if (response != 0) {
var expedition = <?php echo __("'L\'expdition n\'a pas pu tre cre'", 'mondialrelay-wordpress') ?>;
var erreur = <?php echo __("'Erreur'", 'mondialrelay-wordpress') ?>;
jQuery('#mr-notif').addClass('update-nag').css({ "margin": "0", "display": "block" }).html("<strong>"+expedition+"</strong><br>"+erreur+" "+response).show();
}
else {
var expedition = <?php echo __("'L\'expdition a t cre'", 'mondialrelay-wordpress') ?>;
jQuery('#mr-notif').addClass('updated').css({ "padding": "11px 15px" }).html("<strong>"+expedition+"</strong>").show();
jQuery('#mr-form').hide();
jQuery('#mr-text').show();
window.location.reload();
}
console.log(response);
});
});
});
</script>
<?php }
// Expedition creation in a Mondial Relay order (AJAX)
function expedition_callback() {
global $wpdb;
$prefixe = $wpdb->prefix;
// Get the debug mode
$mondialrelay_debug = get_option('mondialrelay_debug', class_MRWP_main::DEBUG);
// Get the order number
$order_id = intval( $_POST['order'] );
// Get the Mondial Relay parameters
$params_compte = class_MRWP_order::get_params_compte();
// Mondial Relay WebService
$client = new SoapClient(class_MRWP_main::MONDIALRELAY_WEBSERVICE);
// Get the Mondial Relay point
$id_mondial_relay = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Parcel Shop ID');
if ((isset($id_mondial_relay) && $id_mondial_relay)) {
$explode_id_mondial_relay = explode('-', $id_mondial_relay);
$params_livraison = class_MRWP_order::get_params_livraison();
$params_livraison['liv_rel_pays_mondial_relay'] = $explode_id_mondial_relay[0];
$params_livraison['liv_rel_mondial_relay'] = $explode_id_mondial_relay[1];
} else {
$params_livraison['liv_rel_pays_mondial_relay'] = '';
$params_livraison['liv_rel_mondial_relay'] = '';
}
// Get the sender parameters
$params_expediteur = class_MRWP_order::get_params_expediteur();
// Get the recipient parameters
$params_destinataire = class_MRWP_order::get_params_destinataire($order_id);
// Hook to change the expedition address
$params_destinataire = apply_filters( 'mrwp_chg_expe_add', $params_destinataire, $order_id);
// Remove accents
foreach($params_destinataire as $key => $champ) {
$params_destinataire[$key] = remove_accents($champ);
}
// Split adress if more than 32 characters
$numchar = strlen($params_destinataire['_shipping_address_1']);
if ($numchar > 32 ) {
$numcut = strrpos($params_destinataire['_shipping_address_1'],' ', -($numchar - 30));
$params_destinataire['_shipping_address_2'] = substr($params_destinataire['_shipping_address_1'], $numcut + 1, $numchar);
$params_destinataire['_shipping_address_1'] = substr($params_destinataire['_shipping_address_1'], 0, $numcut);
}
if (strlen($params_destinataire['_shipping_company']) > 32 ) {
$params_destinataire['_shipping_company'] = substr($params_destinataire['_shipping_company'], 0, 31);
}
// Remove quotes (') on Dest_Ad3 parameter for the Mondial Relay webservice
$params_destinataire['_shipping_address_1'] = str_replace("'", " ", $params_destinataire['_shipping_address_1']);
// Remove CRLF codes and specials characters for the Mondial Relay webservice
$elim = array("'", "", "", "", "", "", "(", ")", "+", "''", '"', "'");
$params_destinataire['_shipping_full_name'] = str_replace("\n","", $params_destinataire['_shipping_full_name']);
$params_destinataire['_shipping_full_name'] = str_replace("\r","", $params_destinataire['_shipping_full_name']);
$params_destinataire['_shipping_full_name'] = str_replace($elim, " ", $params_destinataire['_shipping_full_name']);
$params_destinataire['_shipping_company'] = str_replace("\n","", $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_company'] = str_replace("\r","", $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_company'] = str_replace(""," ", $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_company'] = str_replace($elim, " ", $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_company'] = preg_replace("/@/", ' ', $params_destinataire['_shipping_company']);
$params_destinataire['_shipping_address_1'] = str_replace("\n","", $params_destinataire['_shipping_address_1']);
$params_destinataire['_shipping_address_1'] = str_replace("\r","", $params_destinataire['_shipping_address_1']);
$params_destinataire['_shipping_address_1'] = str_replace($elim, " ", $params_destinataire['_shipping_address_1']);
$params_destinataire['_shipping_address_2'] = str_replace("\n","", $params_destinataire['_shipping_address_2']);
$params_destinataire['_shipping_address_2'] = str_replace("\r","", $params_destinataire['_shipping_address_2']);
$params_destinataire['_shipping_address_2'] = str_replace($elim, " ", $params_destinataire['_shipping_address_2']);
$params_destinataire['_shipping_city'] = str_replace("\n","", $params_destinataire['_shipping_city']);
$params_destinataire['_shipping_city'] = str_replace("\r","", $params_destinataire['_shipping_city']);
$params_destinataire['_shipping_city'] = str_replace($elim, " ", $params_destinataire['_shipping_city']);
$params_destinataire['_shipping_postcode'] = str_replace("\n","", $params_destinataire['_shipping_postcode']);
$params_destinataire['_shipping_postcode'] = str_replace("\r","", $params_destinataire['_shipping_postcode']);
$params_destinataire['_shipping_postcode'] = str_replace($elim, " ", $params_destinataire['_shipping_postcode']);
$params_destinataire['_shipping_country'] = str_replace("\n","", $params_destinataire['_shipping_country']);
$params_destinataire['_shipping_country'] = str_replace("\r","", $params_destinataire['_shipping_country']);
$params_destinataire['_shipping_country'] = str_replace($elim, " ", $params_destinataire['_shipping_country']);
// Get the order parameters
$params_commande =class_MRWP_order::get_params_commande();
$params_commande['ModeCol'] = class_MRWP_main::MODE_COL;
$params_commande['ModeLiv'] = class_MRWP_db::get_meta_champ($order_id, 'Mondial Relay Shipping Code');
$params_commande['NDossier'] = $order_id;
$params_commande['NClient'] = apply_filters( 'mrwp_add_nclient', $params_commande['NClient']);
// Get assurance
$assurance = intval( $_POST['Assurance'] );
// Get the collect point parameters
$params_collecte = class_MRWP_order::get_params_collecte();
// Expedition parameters
$params = array(
'Enseigne' => $params_compte['mondialrelay_code_client']
,'ModeCol' => $params_commande['ModeCol']
,'ModeLiv' => $params_commande['ModeLiv']
,'NDossier' => $params_commande['NDossier']
,'NClient' => $params_commande['NClient']
,'Expe_Langage' => $params_expediteur['mondialrelay_vendeur_langage']
,'Expe_Ad1' => $params_expediteur['mondialrelay_vendeur_adresse1']
,'Expe_Ad2' => $params_expediteur['mondialrelay_vendeur_adresse2']
,'Expe_Ad3' => $params_expediteur['mondialrelay_vendeur_adresse3']
,'Expe_Ad4' => $params_expediteur['mondialrelay_vendeur_adresse4']
,'Expe_Ville' => $params_expediteur['mondialrelay_vendeur_ville']
,'Expe_CP' => $params_expediteur['mondialrelay_vendeur_cp']
,'Expe_Pays' => $params_expediteur['mondialrelay_vendeur_pays']
,'Expe_Tel1' => $params_expediteur['mondialrelay_vendeur_tel']
,'Expe_Tel2' => $params_expediteur['mondialrelay_vendeur_tel2']
,'Expe_Mail' => $params_expediteur['mondialrelay_vendeur_email']
,'Dest_Langage' => $params_destinataire['_shipping_langage']
,'Dest_Ad1' => $params_destinataire['_shipping_full_name']
,'Dest_Ad2' => $params_destinataire['_shipping_company']
,'Dest_Ad3' => $params_destinataire['_shipping_address_1']
,'Dest_Ad4' => $params_destinataire['_shipping_address_2']
,'Dest_Ville' => $params_destinataire['_shipping_city']
,'Dest_CP' => $params_destinataire['_shipping_postcode']
,'Dest_Pays' => $params_destinataire['_shipping_country']
,'Dest_Tel1' => $params_destinataire['_billing_phone']
,'Dest_Mail' => $params_destinataire['_billing_email']
,'Poids' => $params_commande['Poids']
,'Longueur' => $params_commande['Longueur']
,'Taille' => $params_commande['Taille']
,'NbColis' => $params_commande['NbColis']
,'CRT_Valeur' => $params_commande['CRT_Valeur']
,'CRT_Devise' => $params_commande['CRT_Devise']
,'Exp_Valeur' => $params_commande['Exp_Valeur']
,'Exp_Devise' => $params_commande['Exp_Devise']
,'COL_Rel_Pays' => $params_collecte['col_rel_pays_mondial_relay']
,'COL_Rel' => $params_collecte['col_rel_mondial_relay']
,'LIV_Rel_Pays' => $params_livraison['liv_rel_pays_mondial_relay']
,'LIV_Rel' => $params_livraison['liv_rel_mondial_relay']
,'TAvisage' => $params_commande['TAvisage']
,'TReprise' => $params_commande['TReprise']
,'Montage' => $params_commande['Montage']
,'TRDV' => $params_commande['TRDV']
//,'Instructions' => $params_commande['Instructions']
,'Instructions' => ''
,'Assurance' => $assurance
);
// Generation of the security key
$code = implode("", $params);
$code .= $params_compte['mondialrelay_cle_privee'];
$params["Security"] = strtoupper(md5($code));
// Expedition creation
// Si le num d'exp existe dj, alors message d'erreur, sinon cration d'expdition
$expe_exist = class_MRWP_db::get_meta_champ($order_id, 'ExpeditionNum');
if ($expe_exist) {
$callback = 421;
} else {
try{
$expedition = $client->WSI2_CreationExpedition($params)->WSI2_CreationExpeditionResult;
$callback = $expedition->STAT;
} catch(Exception $e){
$debug_except .= $e;
$callback = 789;
}
}
// Statut code
if ($callback != 0) {
echo $callback . '<br>' . class_MRWP_helpers::statut($callback);
if ($mondialrelay_debug) {
if ($callback == 789) {
class_MRWP_helpers::VarPrint($debug_except);
}
class_MRWP_helpers::VarPrint($params);
}
}
elseif ($callback == 0) {
// Add the Mondial Relay expedition paramaters in the database
$champs_bdd = class_MRWP_order::get_expedition_champs($expedition, $params_commande['NbColis']);
class_MRWP_db::insert_meta_champs($order_id, $champs_bdd);
// Get the Mondial Relay email
$email = class_MRWP_order::get_params_emails($order_id);
// Hook creation after db updated
do_action('MRWP_after_expedition_creation', $order_id);
// Update the checkout status
$checkout_status = get_option( 'mondialrelay_state_order', '' );
if ($checkout_status) {
$order = new WC_Order($order_id);
if (!empty($order)) {
$order->update_status($checkout_status);
}
}
// br in html
$email['message'] = nl2br($email['message']);
// Check if email send is activated
if ($email['send'] == 1) {
$destinataire = $params_destinataire['_billing_email'];
// Send the Mondial Relay tracking email to the client
$mail = wc_mail($destinataire, $email['sujet'], $email['message']);
}
// Hook creation after db updated
do_action('MRWP_after_order_status_updated', $order_id);
}
die();
}
// Javascript script for the tracking of the Mondial Relay expedition
function tracking_javascript() { ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
jQuery('.mondialrelay-tracking-button').on('click', function(e) {
var th = jQuery(this);
var order = th.attr('data-order');
var expedition = th.attr('data-expedition');
var langue = th.attr('data-langue');
var data = {
'action': 'tracking',
'order': order,
'expedition': expedition,
'langue': langue
};
$.post(ajaxurl, data, function(response) {
var obj = JSON.parse(response);
//console.log(obj);
var jsonObj = JSON.parse(obj.content);
var jsonPretty = JSON.stringify(jsonObj, null, '\t');
if (obj.response) {
jQuery('#mondial_relay_tracking_notif').addClass('updated').css({ "padding": "11px 15px" }).html(obj.notification).show();
jQuery('#mondial_relay_tracking_Libelle01').html('<strong>' + obj.content.Libelle01 + '</strong>');
jQuery('#mondial_relay_tracking_Relais_Libelle').html('<strong>' + obj.content.Relais_Libelle + '</strong>');
jQuery('#mondial_relay_tracking_Relais_Num').html('<strong>' + obj.content.Relais_Num + '</strong>');
jQuery('#mondial_relay_tracking_Libelle02').html('<strong>' + obj.content.Libelle02 + '</strong>');
var tracing_view = '<table class="wp-list-table widefat fixed striped"><tbody>';
for (var i = 0; i < tracing.length; i++){
var table = tracing[i];
tracing_view += '<tr><td colspan="2"><strong>vnement ' + i + '</strong></td></tr>';
for (var key in table) {
var tracing_libelle = key.replace('Tracing_', '');
tracing_view += '<tr>';
tracing_view += '<td width="60%" style="text-align: left">' + tracing_libelle + '</td>';
tracing_view += '<td width="40%" style="text-align: right"><strong>' + table[key] + '</strong></td>';
tracing_view += '</tr>';
}
}
tracing_view += '</tbody></table>';
//console.log(tracing_view);
jQuery('#mondial_relay_tracking_tracing').html(tracing_view);
jQuery('#mondial_relay_tracking_content').show();
}
else {
jQuery('#mondial_relay_tracking_notif').addClass('update-nag').css({ "display": "block" }).html(obj.notification).show();
}
if (obj.debug) {
jQuery('#mondial_relay_tracking_debug').html(jsonPretty);
}
//console.log(response);
});
});
});
</script>
<?php }
// Expedition tracking of a Mondial Relay expedition (AJAX)
function tracking_callback() {
// Get the debug mode
$mondialrelay_debug = get_option('mondialrelay_debug', class_MRWP_main::DEBUG);
// Get the Mondial Relay parameters
$params_compte = class_MRWP_order::get_params_compte();
// Get the shipping parameters
$expedition = $_POST['expedition'];
$order_id = intval( $_POST['order'] );
$shop_location = wc_get_base_location();
$langue = class_MRWP_helpers::get_langue( $shop_location['country'] );
// SOAP
$client = new SoapClient(class_MRWP_main::MONDIALRELAY_WEBSERVICE);
$params = array(
'Enseigne' => $params_compte['mondialrelay_code_client'],
'Expedition' => $expedition,
'Langue' => $langue,
);
// Generation of the security key
$code = implode("", $params);
$code .= $params_compte['mondialrelay_cle_privee'];
$params["Security"] = strtoupper(md5($code));
try{
$tracking = $client->WSI2_TracingColisDetaille($params)->WSI2_TracingColisDetailleResult;
$callback = $tracking->STAT;
} catch(Exception $e){
$debug_except .= $e;
$callback = 789;
}
if ($callback == 0) {
$response = 1;
$notification = 'Succs';
// Correct tracking result
} elseif ($callback == 80 || $callback == 81 || $callback == 82){
$response = 1;
$notification = $callback . ' : ' . class_MRWP_helpers::statut($callback );
update_post_meta($order_id, 'ExpeditionStatus', $callback);
update_post_meta($order_id, 'ExpeditionStatusDate', time());
// Update the status
if ( 82 == $callback ) {
$order_delivered_status = get_option( 'mondialrelay_state_order_delivered', 0 );
$order = new WC_Order($order_id);
if ( '' != $order_delivered_status ) {
$order->update_status( $order_delivered_status );
}
}
// Incorrect tracking result
} elseif ($callback == 83){
$response = 0;
$notification = $callback . ' : ' . class_MRWP_helpers::statut($callback );
update_post_meta($order_id, 'ExpeditionStatus', $callback);
update_post_meta($order_id, 'ExpeditionStatusDate', time());
// Error
} else {
$response = 0;
$notification = $callback . ' : ' . class_MRWP_helpers::statut($callback );
if ($mondialrelay_debug) {
$notification = $notification . '<br><br>' . print_r($params, true);
}
}
$debug = 0;
if ($mondialrelay_debug) {
$debug = 1;
}
$data = array(
'response' => $response,
'notification' => $notification,
'content' => json_encode( $tracking ),
'debug' => $debug,
);
echo json_encode( $data );
die();
}
}
Function Calls
None |
Stats
MD5 | c813e6566e070fdd055fe5ff3f897151 |
Eval Count | 0 |
Decode Time | 175 ms |